import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-11-07
 * Time: 19:20
 */
//函数式接口

//无返回值，无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
    //void test2();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class Lambda {

    public static void main(String[] args) {
        int size = 10;
        //size = 9; //存在变量捕获不可修改
        OneParameterNoReturn oneParameterNoReturn = (a)->{
            System.out.println(a);
            System.out.println(size);
        };

        PriorityQueue<Integer> minHeap = new PriorityQueue<>(3, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return 0;
            }
        });

        PriorityQueue<Integer> minHeap1 = new PriorityQueue<>(3,(o1,o2)->o1-o2);
    }
    public static void main5(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 10;};
        System.out.println(noParameterReturn.test());


        OneParameterReturn oneParameterReturn = (a)->a + 11;
        System.out.println(oneParameterReturn.test(10));

        MoreParameterReturn moreParameterReturn = (a, b)-> a + b;
        System.out.println(moreParameterReturn.test(1,2));
    }
    public static void main3(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = (a)-> {System.out.println(a);};
        oneParameterNoReturn.test(10);


        MoreParameterNoReturn moreParameterNoReturn = (a,b)->{
            System.out.println(a + b);
        };
        moreParameterNoReturn.test(10, 30);

    }
    public static void main2(String[] args) {
        NoParameterNoReturn parameterNoReturn = ()-> System.out.println();
        parameterNoReturn.test();
    }
    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test(){
                System.out.println("重写方法！");
            }
        };
        noParameterNoReturn.test();
    }
}
